package com.lfk.three.app;

import android.app.Application;

import com.lfk.three.model.FindActlistImp;
import com.lfk.three.model.GetAdImp;
import com.lfk.three.model.SingleManager;
import com.lfk.three.model.TimeLineImp;
import com.lfk.three.static_info.static_info;
import com.lfk.three.utils.crashHandler.CrashHandler;
import com.lfk.three.utils.logger.Logger;
import com.lfk.three.utils.tools.SpUtils;
import com.qiniu.util.Auth;

/**
 * Created by liufengkai on 16/4/9.
 */
public class ThreeApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        // init user message
        SpUtils.init(getApplicationContext());

        init_crashHandler();
        init_info();
        init_SingletonManager();
        init_auth();
        Logger.init();
    }

    /**
     * 更新信息
     */
    private void init_info() {
        if (SpUtils.contains("user_id")) {
            static_info.user_id =
                    (String) SpUtils.get("user_id", "id");
            static_info.user_name =
                    (String) SpUtils.get("user_name", "用户名");
            static_info.user_token =
                    (String) SpUtils.get("user_token", "token");
            static_info.user_image =
                    ((String) SpUtils.get("user_img", "img"));
            static_info.user_sex =
                    (boolean) SpUtils.get("user_sex", true);
            static_info.user_sign =
                    (String) SpUtils.get("user_sign", "sign");
        }
    }

    private void init_crashHandler() {
        CrashHandler.getInstance().init(this);
//        CrashHandler.getInstance().setRestartActivity();
    }

    private void init_SingletonManager() {
        SingleManager.registerService("get_act", FindActlistImp.getInstance());
        SingleManager.registerService("get_ad", GetAdImp.getInstance());
        SingleManager.registerService("get_timeline", TimeLineImp.getInstance());
    }

    private void init_auth() {
        static_info.user_auth =
                Auth.create("nBoSJzs-AzZY4xW_1-VS7zO5oAtCvN3K_9lAEsUY",
                        "cNPJtgok0CkRLpKflkZsj0BMc8-yK1rCr41aQroV");
    }
}
